package
{
	import component.menu.composite.CompositeMenu;
	import component.menu.composite.CompositeMenuEvent;
	import component.menu.data.MenuData;
	
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	
	import obecto.core.FLApplication;
	import obecto.event.FLEvent;

	[SWF(backgroundColor="0xCDCDCD")]
	public class CompositeMenuSample extends FLApplication
	{
		private var myMenu : CompositeMenu;
		
		public function CompositeMenuSample()
		{
			super();
			
			stage.frameRate = 35;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			
			myMenu = new CompositeMenu();
			myMenu.selectOnClick = false;
			
			myMenu.addEventListener(FLEvent.CREATION_COMPLETE, handleMenuCreationComplete);
			myMenu.addEventListener(CompositeMenuEvent.SELECT_PATH, handleMenuSelectPath);
			
			myMenu.itemsData = [
				new MenuData("item1", false, { label: "Item 1", enabled: true }, [
					new MenuData("item1", false, { label: "Item 1-1", enabled: true }),
					new MenuData("item2", false, { label: "Item 1-2", enabled: true }),
					new MenuData("item3", false, { label: "Item 1-3", enabled: true }),
					new MenuData("item4", false, { label: "Item 1-4", enabled: true })]),
				new MenuData("item2", false, { label: "Item 2", enabled: true }, [
					new MenuData("item1", false, { label: "Item 2-1", enabled: true }),
					new MenuData("item2", false, { label: "Item 2-2", enabled: true }, [
						new MenuData("item1", false, { label: "2-2-1", enabled: true }),
						new MenuData("item2", false, { label: "2-2-2", enabled: true }),
						new MenuData("item3", false, { label: "2-2-3", enabled: true }),
						new MenuData("item4", false, { label: "2-2-4", enabled: true })]),
					new MenuData("item3", false, { label: "Item 2-3", enabled: true }),
					new MenuData("item4", false, { label: "Item 2-4", enabled: true })]),
				new MenuData("item3", false, { label: "Item 3", enabled: true }, [
					new MenuData("item1", false, { label: "Item 3-1", enabled: true }),
					new MenuData("item2", false, { label: "Item 3-2", enabled: true }),
					new MenuData("item3", false, { label: "Item 3-3", enabled: true }),
					new MenuData("item4", false, { label: "Item 3-4", enabled: true })]),
				new MenuData("item4", false, { label: "Item 4", enabled: true })];
		}
		
		private function handleMenuCreationComplete(e : FLEvent) : void 
		{
			myMenu.x = 100;
			myMenu.y = 110;
			
			addChild(myMenu);
			
			myMenu.show();
		}
		
		private function handleMenuSelectPath(e : CompositeMenuEvent) : void
		{
			trace(e.selectionPath);
			myMenu.selectPath(e.selectionPath);
		}
		
	}
}